package com.fjut.service.impl;

import com.fjut.mapper.VideoVisitorMapper;
import com.fjut.model.vod.VideoVisitor;
import com.fjut.service.VideoVisitorService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fjut.vo.vod.VideoVisitorCountVo;
import org.springframework.stereotype.Service;

import java.util.*;
import java.util.stream.Collectors;

/**
 * <p>
 * 视频来访者记录表 服务实现类
 * </p>
 *
 * @author DengTianxun
 * @since 2023-03-07
 */
@Service
public class VideoVisitorServiceImpl extends ServiceImpl<VideoVisitorMapper, VideoVisitor> implements VideoVisitorService {

    private static final String X_DATA = "xData";
    private static final String Y_DATA = "yData";
    @Override
    public Map<String, Object> findCount(Long courseId, String startDate, String endDate) {
        Map<String, Object> map = new HashMap<>();
        List<VideoVisitorCountVo> countVoList = baseMapper.findCount(courseId,startDate,endDate);
        /**
         * java8 特性
         * 取出每个对象日期转为流方式，再转换为集合
         */
        List<String> dateList = countVoList.stream().map(VideoVisitorCountVo::getJoinTime).collect(Collectors.toList());
        List<Integer> countList = countVoList.stream().map(VideoVisitorCountVo::getUserCount).collect(Collectors.toList());

        map.put(X_DATA,dateList);
        map.put(Y_DATA,countList);

        return map;
    }

}
